import { AuditTConst } from "src/consts/audit_template_const";
import * as Api from 'src/api/net';

const state: ListMsgData = {} as any;
// StateIniter.init(state, 'demo');

state.curr_page = 1;
state.page_size = 15;
state.total_page = 1;
state.total_size = 1;
state.data_list = []
state.type = "";
// vuex

/** 更新数据的 */
const mutations = {
    [AuditTConst.CommitAuditTList](state: ListMsgData, data: ListMsgData): void {
        console.log("aduitT data update", data);
        state.curr_page = data.curr_page;
        state.page_size = data.page_size;
        state.total_page = data.total_page;
        state.total_size = data.total_size;
        state.data_list = data.data_list;
    },

    [AuditTConst.CommitType](state: ListMsgData, data: String): void {
        state.type = data
    }
}

//异步处理
const actions = {
    [AuditTConst.DispatchAuditTList](context: VuexData, data?: any): void {
        Api.AjaxPost(Config.ajaxUrl + "/audit/list.do", data, (res: any) => {
            if (isNoEmptyObject(res.data)) {
                WLCommit(AuditTConst.CommitAuditTList, res.data);
            }
        })
    },
    [AuditTConst.DispatchAuditTQiYong](context: VuexData, data?: any): void {
        let sendData: any = {};
        sendData["id"] = data.id
        sendData["status"] = data.status
        Api.AjaxPost(Config.ajaxUrl + "/audit/status/edit.do", sendData, (res: any) => {
            if (data.flag) {
                if (data.type == "qy") {
                    WLMessage("审核模版启用成功", "success")
                } else if (data.type == "ty") {
                    WLMessage("审核模版停用成功", "success")
                }
                let senData: any = {}
                senData["curr_page"] = state.curr_page
                senData["page_size"] = state.page_size
                WLDispatch(AuditTConst.DispatchAuditTList, senData);
            }
        })
    }
}


export default {
    state,
    mutations,
    actions
}